﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using ARR.Entities;
//using ARR.UI.QueriesService;
using ARR.UI.Views;
using Telerik.Windows.Controls.Charting;
using ARR.UI.ViewModels;
using Telerik.Windows.Controls;

namespace ARR.UI
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            DataContext = new MainWindowViewModel();

            StyleManager.ApplicationTheme = new Windows7Theme();

            InitializeComponent();
        }

        private void TestAreaButton_Click(object sender, RoutedEventArgs e)
        {
            TestAreaView view = new TestAreaView();
            view.Show();

        }

        private void Charts_Click(object sender, RoutedEventArgs e)
        {
            int x = 19;
            int y = 1;

            int total = x + y;
        }

        private void RadRibbonButton_Click(object sender, RoutedEventArgs e)
        { 
        
        }

        private void UpdateStatusRadRibbonButton_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("El siguiente proceso actualizará el Status de todos los SKUs del RangeReview actual. Esta acción sobreescribirá el status actual. Está seguro que desea continuar?", "Actualización Status", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {
                ArticlesService.ArticlesServiceClient service = new ArticlesService.ArticlesServiceClient();
                try
                {
                    service.UpdateStatus(WorkspaceData.Instance.RangeReview.Id);
                    service.Close();
                }
                catch
                {
                    service.Abort();
                    throw;
                }
                finally
                {
                    MessageBox.Show("El proceso ha concluido con éxito", "Actualización Status", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }

        //private void TestButton_Click(object sender, RoutedEventArgs e)
        //{
        //    //Reports.SameStoreComparison comp = new Reports.SameStoreComparison();
        //    //comp.Render();

        //    System.Windows.Documents.TextRange tr = new System.Windows.Documents.TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
        //    using (MemoryStream ms = new MemoryStream())
        //    {
        //        //tr.Save(ms, DataFormats.Rtf);
        //        tr.Save(ms, DataFormats.Xaml);
        //        using (StreamReader reader = new StreamReader(ms))
        //        {
        //            string text = "<FlowDocument>" + System.Text.ASCIIEncoding.Default.GetString(ms.ToArray()) + "</FlowDocument>";
        //            string contentToBeSaved = HTMLConverter.HtmlFromXamlConverter.ConvertXamlToHtml(text);
        //        }
        //    }
        //}
    }
}
